<template>
  <div>
      <div :class="[$style.search_box, $style.topSelect]">
        <SearchInput
        placeholder="订单编号"
        label="订单编号"
        style="margin-right:20px"
        :value="oid"
        :onChange="(val) => changeSearch('oid',val)"
        :onBlur="queryData"
      />
        <SearchInput
          placeholder="结算单号"
          label="结算单号"
          style="margin-right:20px;"
          :value="stId"
          :onChange="(val) => changeSearch('stId',val)"
          :onBlur="queryData"
        /> 
      
     <div :class="$style.selectBox">
       <label>请选择大客户：</label>
          <el-select
            style="width:200px"
            v-model="uid"
            clearable
            @change="queryData(uid)"
            placeholder="请选择">
            <el-option  label="全部" value=""></el-option>
            <el-option v-for="item in company" :key="item.id" :label="item.name" :value="item.id+''"></el-option>
          </el-select>
      </div>
      <div :class="$style.selectBox" style="display: flex;align-items: center;">
        <label>时间：</label>
        <el-date-picker
          v-model="appointmentTime"
          type="datetimerange"
          @change="queryData"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="timestamp"
          :picker-options="pickerOptions"
        ></el-date-picker>
      </div>

      </div>
    <Panel title="大客户余额日志" useBack>
      <TableEncapsulation
        slot="body"
        :changeSelectRow="(ids) => multipleSelection = ids"
        :tableConfig="tableConfig"
        :tableData="tableData"
      >
        <template slot="operation" slot-scope="operation">
          <el-button type="text" @click="()=>nav(operation.row)">--</el-button>
        </template>
        <TablePager
          slot="pager"
          v-if="pager.use"
          :size="pager.size"
          :pageChange="pageChange"
          :show-total="pager.showTotal"
          :total="pager.total"
          :current="pager.current"
        >
          <span class="demonstration">GO></span>
        </TablePager>
      </TableEncapsulation>
    </Panel>

  </div>
</template>

<script>
import request from "@/tools/request";
import Panel from "@/components/Panel";
import TableEncapsulation from "@/components/TableEncapsulation";
import SearchInput from "@/components/SearchInput";
import TablePager from "@/components/Pager";
import ModifyForm from "@/components/ModifyForm";
import ModalPanel from "@/components/ModalPanel";
import { objectFilter } from "@/tools/array";
import { dateFormat } from "@/tools/time";

export default {
  name:'companyBalance_',
  components: {
    Panel,
    TableEncapsulation,
    SearchInput,
    TablePager,
    ModalPanel,
    ModifyForm
  },
  data() {
    return {
      pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
      },
      appointmentTime: null,
      keywords: '',
      company:[],
      topUpEditColumn: [
        {
          name: "操作对象",
          prop: "userName",
          slotName: "userName",
          type: "other",
          width: 24,
        },
        {
          name: "类型",
          prop: "type",
          type: "other",
          slotName: "type",
          width: 24,
          required: true
        },
        {
          name: "金额",
          prop: "amount",
          type: "number",
          width: 24,
          required: true
        }
      ],
      operation: true,
      account: "",
      accountStatus: "",
      multipleSelection: [],
      nickName: "",
      uid:'',
      pager: {
        use: true,
        total: 0,
        current: 1,
        size: 10,
        showTotal: true
      },
      tableData: [],
      page:1,
      stId: '',
      oid: '',
      uid: '',
    };
  },
  computed: {
    tableConfig() {
      return {
        selection: false,
        columnConfig: [
          {
            type: "text",
            prop: "oid",
            label: "订单编号",
            align: "center",
          },
          {
            label: "变动金额",
            type: "text",
            prop: "change",
            align: "center"
          },
          {
            label: "变动前",
            type: "text",
            prop: "before",
            align: "center"
          },
          {
            label: "变动后",
            type: "text",
            prop: "after",
            align: "center"
          },
          {
            label: "类型",
            type: "other",
            prop: "type",
            align: "center",
            fnc: val => val == 1 ? "充值余额":val == 2 ? "充电消费":val == 3 ? "授信余额":"附加费消费",
            class:val => val == 1 ? "agree":val == 2 ? "wait":val == 3 ? "blue-tag":"refuse",
          },
          {
            label: "结算单号",
            type: "text",
            prop: "stId",
            align: "center",
        
          },
          {
            label: "变动时间",
            type: "text",
            prop: "createTime",
            align: "center",
        
          },
        //   this.operation && {
        //     type: "operation",
        //     align: "center",
        //     label: "操作"
        //   }
        ].filter(Boolean)
      };
    }
  },
  methods: {
    nav(rowData){
      this.$router.push({
        path: '/user-order',
        query: {
          userId:rowData.id,
          userName: rowData.nickName
        }
      })
    },
    changeSearch(key, val) {
      this[key] = val;
      this.pager.current = 1;
    },
    balance(rowData) {
      this.$router.push({
        path: "/log/group/wallet/list",
        query: {
          uid: rowData.id
        }
      })
    },
    changeKeuWord(val){
      this.keywords = val
      this.pager.current=1
    },
    pageChange(val) {
      this.pager.current = val
      this.queryData()
    },
    //第三方公司
    async companyTh(){
      let { list } = await request({
      url: "/company/group/select",
      method: "POST",
      data: {}
      });
      this.company = list
    },
    async queryData(){
        let endTime = this.appointmentTime ? (dateFormat(this.appointmentTime[1] + 86400000-1, "yyyy-MM-dd HH:mm:ss")) : undefined
        let beginTime = this.appointmentTime ? (dateFormat(this.appointmentTime[0],"yyyy-MM-dd HH:mm:ss")) : undefined
        let stId =  this.stId
        let oid = this.oid
        let uid = this.uid
        let page = this.pager.current
        let search = objectFilter({beginTime, endTime, stId, oid, page, uid})
        let res = await request({
        url: "/log/group/wallet/list",
        method: "POST",
        data: search
        });
        this.tableData = res.page.list
        this.pager.total = res.page.totalCount
        this.pager.current = res.page.currPage
       // this.$set(this.pager,'total',res.total>>>0)
    },
  }, 
  created() {
    this.uid = this.$route.query.id 
    this.queryData()
    this.companyTh()
  }
};
</script>

<style lang='scss' module>
.modifyStyle{

}
.search_box {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  // flex-direction: row-reverse;
  
  :global{
    .el-input{
      width: 250px;
    }
    .el-select{
      .el-input{
        width: 90px;
      }
    }
    .el-input__icon{
      line-height: 32px;
    }
  }
}

.topSelect{
  background-color: white;
  border-radius: 4px;
  padding: 20px;
  margin-bottom: 20px;
}

.selectBox {
  :global {
    label {
      font-size: 14px;
      color: #666666;
    }
    .el-input__inner {
      height: 32px;
    }
    .el-input__suffix {
      line-height: 32px;
    }
    .el-date-editor--datetime{
      width: 200px;
    }
  }
}
</style>